﻿@namespace Bit.BlazorUI
@inherits BitComponentBase
@typeparam TItem

@{
    var template = ItemTemplate ?? ChildContent;
}

<div @ref="RootElement" @attributes="HtmlAttributes"
     id="@_Id"
     style="@StyleBuilder.Value"
     class="@ClassBuilder.Value"
     dir="@Dir?.ToString().ToLower()">
    @if (template is not null)
    {
        foreach (var item in _currentItems)
        {
            @template(item)
        }
    }

    @if (_isLoading is false && _currentItems.Count == 0)
    {
        if (EmptyTemplate is null)
        {
            <div class="bit-isc-emp">There is no item</div>
        }
        else
        {
            @EmptyTemplate
        }
    }

    <div @ref="_lastElementRef"
         class="@LastElementClass"
         style="@GetLastElementStyle()">
    </div>

    @if (_isLoading)
    {
        @if (LoadingTemplate is null)
        {
            <div class="bit-isc-ldg">Loading...</div>
        }
        else
        {
            @LoadingTemplate
        }
    }
</div>
